package CRUD;

// default package
// Generated Apr 21, 2011 3:13:26 PM by Hibernate Tools 3.3.0.GA

import Utility.SessionFactoryUtil;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import xmlMapping.Member;
import xmlMapping.Suspend;
/**
 * Home object for domain model class Suspend.
 * @see .Suspend
 * @author Hibernate Tools
 */
public class SuspendHome {

	private static final Log log = LogFactory.getLog(SuspendHome.class);  
      	public Session session;

       public SuspendHome() {
              if(session==null|| !session.isOpen())
           
        session=SessionFactoryUtil.getSessionFactory().openSession();
       
       }
  
	public void persist(Suspend transientInstance) {
       
                session.beginTransaction();
            log.debug("persisting Suspend instance");
		try {
			session.persist(transientInstance);
                         session.getTransaction().commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Suspend instance) {
       
                session.beginTransaction();
		log.debug("attaching dirty Suspend instance");
		try {
			session.saveOrUpdate(instance);
                         session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Suspend instance) {
       
                session.beginTransaction();
		log.debug("attaching clean Suspend instance");
		try {
			session.lock(instance, LockMode.NONE);
                         session.getTransaction().commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Suspend persistentInstance) {
       
                session.beginTransaction();
		log.debug("deleting Suspend instance");
		try {
			session.delete(persistentInstance);
                         session.getTransaction().commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Suspend merge(Suspend detachedInstance) {
       
                session.beginTransaction();
		log.debug("merging Suspend instance");
		try {
			Suspend result = (Suspend) session.merge(detachedInstance);
                         session.getTransaction().commit();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Suspend findById(java.lang.Integer id) {
       
                session.beginTransaction();
		log.debug("getting Suspend instance with id: " + id);
		try {
			Suspend instance = (Suspend) session
					.get(Suspend.class, id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Suspend instance) {
       
                session.beginTransaction();
		log.debug("finding Suspend instance by example");
		try {
			List results = session.createCriteria(
					Suspend.class).add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
        public List checkSuspend(Member mem){
       
                session.beginTransaction();
             Criteria crit=  session.createCriteria(Suspend.class);
             Criterion uId=Restrictions.eq("memberByMemberId", mem);
             crit.add(uId);
             return crit.list();
        }

       
}
